<?php
       class addbook extends template{
           private $db;
           private $info;
           
           function __construct($db,$info)
           { 
             $this->db=$db;   
             $this->info=$info;
             $this->db->get_connect();
           }
           function getmyshelf()
           {
            $arraydata=array();
            $sql="SELECT
            tb_user.shelfid
            FROM
            tb_user
            where tb_user.oauth='".$_COOKIE['oauth']."' and tb_user.roleid=1 ";
            $arrayshelf=$this->db->db_set_recordset($sql);
            
            if($arrayshelf[0]['shelfid']||($this->checkadmin()&&$_GET['shelfid']))
            {
            if($arrayshelf[0]['shelfid'])
            {
              $shelfid=$arrayshelf[0]['shelfid'];
            }else
            {
            
              $shelfid=$_GET['shelfid'];
            }
            
            
            
            $sql=" SELECT * FROM `tb_cat` where tb_cat.shelfid=$shelfid ";
            $arraycat=$this->db->db_set_recordset($sql);
            
            
            $arraydata['cat']=$arraycat;
            
            
            
            $sql=" SELECT * FROM `tb_tag` where tb_tag.shelfid=$shelfid order by tb_tag.`name` asc   ";
            $arraytag=$this->db->db_set_recordset($sql);
            
            
            $arraydata['tag']=$arraytag;
            
            
            $arraydata['shelfid'] = $shelfid;
            
            //return   $arraydata;
            }else
            {
            $this->db->closedb();  
            header("Location: ".baseinfo); 
            
            }
            
            
            
             
            
            return      $arraydata;
              
           }
           function view(){ 
             $this->setdb($this->db); 
             $data['shelf']=$this->getmyshelf();
             $data['userlist']=$this->getuserlistbyshelfid($data['shelf']['shelfid']);
              $this->db->closedb();  
             if($_GET['bookid'])
             {
               $this->db->get_connect();
               $this->setdb($this->db);
               
               $data['editbook']=$this->getbookbybookid($_GET['bookid']);
               $this->db->closedb();
             }
             
             $this->setdata($data);
             $this->load('addbook');
           
           }
        
        
        }
?>
